/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication5.controller;

import java.util.ArrayList;
import javaapplication5.model.AddressBookModel;
import javaapplication5.model.Contact;
import javax.swing.JTextField;
import view.AddressBookView;

/**
 *
 * @author mathieubakrim
 */
public class AddressBookController {
    
    private AddressBookModel theModel;

    
    public AddressBookController(AddressBookModel theModel) {    
        this.theModel = theModel;
    }
    
    public String[] getGroup(){
        return theModel.getGroup();
    }
    /**
     * 
     * @return List of contacts 
     **/
    public ArrayList<Contact> getContactsList() {
        return theModel.getContactsList();
    }
    
    /**
     * Create a contact with datas read from the view
     * @param in: array of the Createform's textfields
     * @param out: an Object Contact, saved in controller arraylist
     **/
    public Contact createContact(JTextField[] tab_textField, String grp) {
       String ln = tab_textField[0].getText();
       String fn = tab_textField[1].getText();
       String pn = tab_textField[2].getText();
       String ap = tab_textField[3].getText();
       String ape = tab_textField[4].getText();
       String hp = tab_textField[5].getText();
       String ep = tab_textField[6].getText();
       String epe = tab_textField[7].getText();
       String gr = grp;
       
       
       System.out.println(ln + fn + pn);
        
        return theModel.createContact(ln, fn, pn, ap, ape, hp, ep, epe, gr);
    }
    
    /**
     * Delete a contact
     * @Todo : destroy the object after removing it from the list
     **/
    public void deleteContact(Contact c){
        theModel.deleteContact(c);
    }
}
